<div class="row" style="margin-top:20px;">

	<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Add A User</a></li>
		<li><a href="#tabs-2">Import Users</a></li>
	</ul>
	<div id="tabs-1">
		<div>
			<form action="<?php echo site_url('admin/manage_users'); ?>" method="POST">
				
				<label for="qut_id">QUT ID (Student Number, Staff Number, etc.)</label>
				<input type="text" name="qut_id">

				<br>

				<label for="first_name">First Name</label>
				<input type="text" name="first_name">

				<br>

				<label for="last_name">Last Name</label>
				<input type="text" name="last_name">

				<br>

				<label for="role">Role</label>
				<select name="role" id="add_user_role">
					<option value="student">Student</option>
					<option value="tutor">Tutor</option>
					<option value="lecturer">Lecturer</option>
					<option value="administrator">Administrator</option>
				</select>

				<br>

				<div id="class_select_wrapper">
					<label for="class_id">Select the Students Class:</label>
					<select name="class_id" id="class_id">
						<option value="0">Add to unit only.</option>
						<?php foreach ($class_data as $class) : ?>
							<option value="<?php echo $class['class_id']; ?>"><?php echo $class['location'] . ' ' . ucfirst($class['day']) . ' ' . $class['start_time']; ?></option>
						<?php endforeach; ?>
					</select>
				</div>

				<br>

				<label for="email">Email</label>
				<input type="text" name="email">

				<br>

				<div class="note left">Note: Passwords will be automatically generaed and emailed to users after their account is created.</div>

				<br>

				<input type="submit" value="Add User">

			</form>
		</div>
	</div>
	<div id="tabs-2">
		<div>
			<form action="<?php echo site_url('admin/manage_users'); ?>" method="POST" enctype="multipart/form-data" >

				<label for="role">Role</label>
				<select name="role" id="import_users_role">
					<option value="student">Student</option>
					<option value="tutor">Tutor</option>
					<option value="lecturer">Lecturer</option>
				</select>

				<br>

				<div id="import_user_class_select_wrapper">
					<label for="class_id">Select the Students Class:</label>
					<select name="class_id" id="class_id">
						<option value="0">Add to unit only.</option>
						<?php foreach ($class_data as $class) : ?>
							<option value="<?php echo $class['class_id']; ?>"><?php echo $class['location'] . ' ' . ucfirst($class['day']) . ' ' . $class['start_time']; ?></option>
						<?php endforeach; ?>
					</select>
				</div>

				<br>

				<label for="file">CSV File</label>
				<input type="file" name="userfile" size="20" />

				<br />

				<input type="hidden" name="upload" value="1" />
				<input type="submit" value="Upload and Import" />

			</form>
		</div>	
	</div>
</div>

</div>

<div class="clear"></div>

<h1>View Users</h1>
<div>

<table>
	
	<tr>
		<th>QUT ID</th>
		<th>Full Name</th>
		<th>Email</th>
		<th>Role</th>
		<th>Options</th>
	</tr>

	<?php foreach ($user_data as $key => $user): ?>
		<tr style="border-bottom:1px solid #aaa;">
			<td><?php echo $user['qut_id']; ?></td>
			<td><?php echo $user['first_name'] . ' ' . $user['last_name']; ?></td>
			<td><?php echo $user['email']; ?></td>
			<td><?php echo $user['role']; ?></td>
			<td><a href="#" class="show_user_options">Show Options</a></td>
		</tr>
		<tr class="user_options" style="display:none;">
			<td colspan="5">
				<table>
					<tr>
						<td>
							<strong>User Info:</strong><br>
							User ID: <?php echo $user['user_id']; ?><br>
							QUT ID: <?php echo $user['qut_id']; ?><br>
							First Name: <?php echo $user['first_name']; ?> <br>
							Last name: <?php echo $user['last_name']; ?> <br>
							Email: <?php echo $user['email']; ?> <br>
							Role: <?php echo ucfirst( $user['role'] ); ?> <br>
							Result: <?php echo $user['result']; ?> <br>
							%: <?php echo $user['%']; ?>
						</td>
						<td>
							<strong>Class Info:</strong><br>
							<?php if ( isset($user['class_id']) ) : ?>
							Class ID: <?php echo $user['class_id']; ?><br>
							Location: <?php echo $user['location']; ?><br>
							Day: <?php echo ucfirst( $user['day'] ); ?> <br>
							Start Time: <?php echo $user['start_time']; ?> <br>
							End Time: <?php echo $user['end_time']; ?> <br>
							<?php else : ?>
							<p>User is not enrolled into a class.</p>
						<?php endif; ?>
						</td>
						<td>
							<strong>Manage User:</strong><br>
							<a href="<?php echo site_url('admin/manage_users'); ?>/delete/<?php echo $user['user_id']; ?>">Delete User</a> <br><br>

							<strong>Change Class</strong>
							<?php if ( $user['role'] == 'student' ) : ?>
							<form action="<?php echo site_url('admin/manage_users'); ?>" method="POST">
								<label for="class_id">Select new class:</label>
								<select name="class_id" id="class_id">
									<option value="0">Add to unit only.</option>
									<?php foreach ($class_data as $class) : ?>
										<option value="<?php echo $class['class_id']; ?>"><?php echo $class['location'] . ' ' . ucfirst($class['day']) . ' ' . $class['start_time']; ?></option>
									<?php endforeach; ?>
								</select>
								<br>
								<input type="hidden" name="user_id" value="<?php echo $user['user_id']; ?>" />
								<input type="hidden" name="change_class" value="1" />
								<input type="submit" value="Change Class" />
							</form>
							<?php else: ?>
								<p>Only students can be enrolled into classes.</p>
							<?php endif; ?>
							<p></p>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	<?php endforeach ?>

</table>
	
</div>